package com.intelligentpension.utils

import android.os.Handler
import android.os.Looper
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService

/**
 * 版权：点赞 版权所有
 * author :赵航
 * @e-mail: zhaohangcn@gmail.com
 * time：2022/3/26
 * describe ：
 */
object ThreadUtils {
    private val executor = Executors.newSingleThreadExecutor()
    private val handler = Handler(Looper.getMainLooper())

    /**
     * UI主线程线程池
     */
    @JvmStatic
    fun executeMainThread(runnable: Runnable) {
        handler.post(runnable)
    }

    /**
     * UI子线程线程池.缺点,只要有一个异常,所有子线程全部停止
     */
    @JvmStatic
    fun executeSubThread(runnable: Runnable) {
        executor.execute(runnable)
    }

    /**
     * 定时任务
     */
    fun timerTask(runnable: Runnable) {
        val executor: ScheduledExecutorService = Executors.newScheduledThreadPool(1)
        executor.submit(runnable)
    }
}